<style lang="scss" scoped>
  @import '../../../styles/common/loading.less';
  .container{
    border: none !important;
    margin-top: 4px;
  }
  .el-col-offset-1 {
    margin-left: 0%;
  }
  .button_a {
    background-color: rgba(255, 138, 0, 1);
    border-color: rgba(255, 138, 0, 1);

  }
  .col_a {
    margin-left: 2%;
  }
  .el-card {
    height: 200px;
  }

  .el-button--primary {
    background-color: rgba(255, 138, 0, 1);
    border-color: rgba(255, 138, 0, 1);
  }
</style>
<template>
  <div  class="common-background-color">
    <div>
      <div style="width:98%;height:100%;margin: 6px 12px;">
        <el-collapse v-model="activeNames" v-if="this.item===0||this.item===1" @change="handleChange"  >
          <el-collapse-item title="医疗机构信息管理信息"  name="1">
            <el-form :model="form" :rules="rules" ref="form" class="info-submit-form">
              <el-row type="flex">
                <el-col :span="8">
                  <el-form-item prop="hospCode" label="医疗机构编码" >
                    <el-input  v-model="form.hospCode"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item prop="hospTypeName" label="医疗机构名称" >
                    <el-input  v-model="form.hospTypeName"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item prop="address" label="地址" >
                    <el-input  v-model="form.address"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex">
                <el-col :span="8">
                  <el-form-item prop="organCode" label="组织机构代码" >
                    <el-input  v-model="form.organCode"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item prop="hospLevel" label="医院等级" >
                    <el-select  v-model="form.hospLevel">
                      <el-option
                        v-for="item in HospLevel"
                        :key="item.codeCode"
                        :label="item.codeCName"
                        :value="item.codeCode">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item prop="delFlag" label="有效标志" :formatter="delFlagFormat" >
                    <el-select   v-model="form.delFlag">
                      <el-option
                        v-for="item in ValidFlag"
                        :key="item.codeCode"
                        :label="item.codeCName"
                        :value="item.codeCode">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex">

                <el-col :span="8">
                  <el-form-item prop="legalPerName" label="法人姓名" >
                    <el-input  v-model="form.legalPerName"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item prop="legalPerNo" label="法人身份号码" >
                    <el-input  v-model="form.legalPerNo"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item prop="legalPerMobile" label="法人电话" >
                    <el-input  v-model="form.legalPerMobile"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex">

                <el-col :span="8">
                  <el-form-item prop="licenseKey" label="执业许可证号" >
                    <el-input  v-model="form.licenseKey"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item prop="districtCode" label="所属行政区代码" >
                    <el-input  v-model="form.districtCode"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item prop="PZRQ" label="批准日期" >
                    <el-date-picker v-model="form.PZRQ" type="datetime" placeholder="选择日期时间" ></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex">
                <el-col :span="8">
                  <el-form-item prop="endDate" label="截止日期" >
                    <el-date-picker v-model="form.endDate" type="datetime" placeholder="选择日期时间" ></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item prop="hospCorwd" label="医疗服务人群" >
                    <el-input  v-model="form.hospCorwd"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item prop="hospCorwdScope" label="医疗服务范围" >
                    <el-input  v-model="form.hospCorwdScope"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex">
                <el-col :span="8">
                  <el-form-item prop="hospCorwdContent" label="医疗服务内容" >
                    <el-input  v-model="form.hospCorwdContent"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item prop="linkerMobile" label="联系电话" >
                    <el-input  v-model="form.linkerMobile"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item prop="zipCode" label="邮政编码" >
                    <el-input  v-model="form.zipCode"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex">
                <el-col :span="8">
                  <el-form-item prop="remark" label="备注" >
                    <el-input  v-model="form.remark"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-collapse-item>
        </el-collapse>
        <el-collapse v-model="activeNames" v-if="this.item===2" @change="handleChange"  >
          <el-collapse-item title="医疗机构信息管理信息"  name="1">
            <el-form :model="form" label-width="110px">
              <el-row type="flex" >
                <el-col :span="8">
                  <el-form-item label="医疗机构编码" >
                    <el-input disabled  v-model="form.hospCode"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item label="医疗机构名称" >
                    <el-input disabled  v-model="form.hospTypeName"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item label="地址" >
                    <el-input disabled  v-model="form.address"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex">
                <el-col :span="8">
                  <el-form-item label="组织机构代码" >
                    <el-input disabled  v-model="form.organCode"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item label="医院等级" >
                    <el-select disabled  v-model="form.hospLevel">
                      <el-option
                        v-for="item in HospLevel"
                        :key="item.codeCode"
                        :label="item.codeCName"
                        :value="item.codeCode">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item label="有效标志" :formatter="delFlagFormat" >
                    <el-select disabled   v-model="form.delFlag">
                      <el-option
                        v-for="item in ValidFlag"
                        :key="item.codeCode"
                        :label="item.codeCName"
                        :value="item.codeCode">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex">
                <el-col :span="8">
                  <el-form-item label="法人姓名" >
                    <el-input disabled  v-model="form.legalPerName"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item label="法人身份号码" >
                    <el-input disabled  v-model="form.legalPerNo"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item label="法人电话" >
                    <el-input disabled  v-model="form.legalPerMobile"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex">
                <el-col :span="8">
                  <el-form-item label="执业许可证号" >
                    <el-input disabled  v-model="form.licenseKey"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item label="所属行政区代码" >
                    <el-input disabled  v-model="form.districtCode"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item label="批准日期" >
                    <el-date-picker disabled v-model="form.PZRQ" type="datetime" placeholder="选择日期时间" ></el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex">
                <el-col :span="8">
                  <el-form-item label="截止日期" >
                    <el-date-picker disabled v-model="form.endDate" type="datetime" placeholder="选择日期时间" ></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item label="医疗服务人群" >
                    <el-input disabled  v-model="form.hospCorwd"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item label="医疗服务范围" >
                    <el-input disabled  v-model="form.hospCorwdScope"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex">
                <el-col :span="8">
                  <el-form-item label="医疗服务内容" >
                    <el-input  disabled v-model="form.hospCorwdContent"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item label="联系电话" >
                    <el-input disabled  v-model="form.linkerMobile"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8" >
                  <el-form-item label="邮政编码" >
                    <el-input disabled  v-model="form.zipCode"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row type="flex">
                <el-col :span="8">
                  <el-form-item label="备注" >
                    <el-input disabled  v-model="form.remark"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-collapse-item>
        </el-collapse>
      </div>
      <div>
        <template>
          <div slot="footer" style="text-align: center;height: 60px;line-height: 30px" class="dialog-footer">
            <el-button type="primary" v-if="this.item===0" @click="save('form')">保 存</el-button>
            <el-button type="primary" v-if="this.item===1" @click="handleEditUpdate('form')">修 改</el-button>
            <el-button type="primary" v-if="this.item===0" @click="resetForm('form')">重 置</el-button>
            <el-button type="info" v-if="this.item===1||this.item===2" @click="fanhui">关 闭</el-button>
          </div>
        </template>
      </div>
    </div>
    <el-dialog
      :visible.sync="Successdialog"
      :show-close="false"
      :close-on-click-modal="true"
      :close-on-press-escape="false"
      width="20%"
      center>
      <div style="margin-top: -35px;">
        <div>| 医疗机构信息管理</div>
        <hr style="width: 80%;margin-left: 1px">
      </div>
      <div v-if="this.item1===0" style="text-align: center;margin-top: 20px">
        <img src="../../../assets/images/pass.png" width="60">
        <div style="margin-top: 10px">{{this.message}}</div>
        <!--        <div style="margin-top: 10px">大病赔案号：{{formInline.caseNo}}</div>-->
      </div>
      <div v-if="this.item1===1" style="text-align: center;margin-top: 20px">
        <img src="../../../assets/images/notPass.png" width="60">
        <div style="margin-top: 10px">提交失败</div>
        <!--        <div style="margin-top: 10px">大病赔案号：{{formInline.caseNo}}</div>-->
      </div>
      <div style="margin-top: 15px;text-align: center"><span style="font-size: x-large">{{time}}</span>秒后跳转到上一个页面</div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="researchCheckSearch" type="text" :disabled="isDisabled">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import * as api from '@/api/basicInformation'
import * as api1 from '@/api/baseDate'
export default {
    name: 'medicalInstitutionMessageDemo',
    inject:['reload'],
    data() {
      return {
        rules:{ // 终止日期不能早于开始日期
          hospCode:[{ required: true, message: '医疗机构编码不能为空', trigger: 'blur' },],
          hospTypeName:[{ required: true, message: '医疗机构名称不能为空', trigger: 'blur' },],
          delFlag:[{ required: true, message: '有效标志不能为空', trigger: 'blur' },],
        },
        HospLevel:[],
        Successdialog:false,
        query: {
          address: '',
          name: '',
          pageIndex: 1,
          pageSize: 10
        },
        ValidFlag:[
          {
            codeCode:0,
            codeCName:'无效'
          },
          {
            codeCode:1,
            codeCName:'有效'
          },
        ],
        PlaceType:[
          {
            codeCode:'1',
            codeCName:'进口'
          },
          {
            codeCode:'2',
            codeCName:'国产'
          },
        ],
        drugCatalog:[
          {comCode: "20000000000",comName:"总公司"},
          {comCode: "20020000000",comName:"江苏分公司"},
          {comCode: "20020100000",comName:"徐州中支公司"},
        ],
        PresFlag:[
          {
            codeCode:'0',
            codeCName:'非处方药'
          },
          {
            codeCode:'1',
            codeCName:'处方药'
          },
        ],
        DiseClass:[],
        DiseType:[],
        SpeDiseClass:[],
        dialogFormVisible:false,
        activeNames: ['1','2'],
        //控制显示隐藏
        isBase:false,
        isSurvey:false,
        shenheyijian:"1",
        activeName: 'first',
        multipleSelection: [],
        delList: [],
        editVisible: false,
        pageTotal: 0,
        form: {
        },
        formInline: {
          policy: '20143301000000008',
          startDate: '2019-01-01',
          endDate: '2022-01-01',
          insurePlan: '徐州医保局',
        },
        message:'',
        time:0,
        item:0,
        item1:0,
      };
    },
    created() {
      this.HospLevel1();
        this.form=JSON.parse(this.$route.query.medicalInstitutionMessageDemo)
      this.item=JSON.parse(this.$route.query.item)
      console.log("123"+this.list)
    },
    mounted() {
      this.restaurants=this.drugCatalog.map(item=>{
        return{
          code:item.comCode,
          value:item.comName,
        }
      })
    },
    methods: {
      querySearchAsync(queryString, cb) {
        var restaurants = this.restaurants;
        var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;

        clearTimeout(this.timeout);
        this.timeout = setTimeout(() => {
          cb(results);
        }, 1000 * Math.random());
      },
      createStateFilter(queryString) {
        return (state) => {
          // return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
          return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) > -1);
        };
      },
      comCode(comName){
        this.drugCatalog.forEach(item=>
          {
            if(comName===item.comName){
              this.list.comCode=item.comCode
            }
          }
        )
      },
      save(formName){
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.comCode(this.list.comName);
            api.getSaveHospCompany(this.form
            ).then(res => {
              this.message=res.data.resultMsg;
              this.Successdialog=true
              // 把time改为5
              this.time = 5;
              // 设定一个定时器，每一秒调用一次coundDown方法，time-1
              setInterval(this.countDown, 1000);
            }).catch((function () {
                /*let THIS = this;*/
                this.item1=1,
                  this.Successdialog=true
                // 把time改为5
                this.time = 5;
                // 设定一个定时器，每一秒调用一次coundDown方法，time-1
                setInterval(this.countDown, 1000);
              }),
            )
          } else {
            console.log('error submit!!');
            return false;
          }
        });

      },
      handleEditUpdate(){
        api.getUpdataHospCompany(this.form
        ).then(res => {
          this.message=res.data.resultMsg;
          this.Successdialog=true
          // 把time改为5
          this.time = 5;
          // 设定一个定时器，每一秒调用一次coundDown方法，time-1
          setInterval(this.countDown, 1000);
        }).catch((function () {
            /*let THIS = this;*/
            this.item1=1,
              this.Successdialog=true
            // 把time改为5
            this.time = 5;
            // 设定一个定时器，每一秒调用一次coundDown方法，time-1
            setInterval(this.countDown, 1000);
          }),
        )
      },
      HospLevel1(){
        var data={
          "codeType": "HospLevel"
        }
        api1.MedType(data
        ).then(res => {
          // debugger
          this.HospLevel=res.data
        })
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
        this.reload();
      },
      fanhui(){
          // this.$router.go(-1)
          this.closePageTo(this.$store,this.$route,this.$router,'medicalInstitutionMessage');
      },
      isBaseInfo(){
        this.isBase=!this.isBase;
      },
      surveyHistory(){
        this.isSurvey=!this.isSurvey;
      },
      // 分页导航
      handlePageChange(val) {
        this.$set(this.query, 'pageIndex', val);
        this.getData();
      },
      onSubmit() {
        console.log('submit!');
      },
      researchCheckSearch(){
        // this.Successdialog=false
        //this.$router.push({name:'medicalInstitutionMessage'});
        this.closePageTo(this.$store,this.$route,this.$router,'medicalInstitutionMessage');
        self.close();
      },
//   封装一个方法
      countDown() {
        let THIS = this;
        THIS.time--;
      },
    },
    watch: {
      //   监听time的值
      time: function (newVal) {
        if (newVal === 0) {
          //this.$router.push({name:'medicalInstitutionMessage'});
          this.closePageTo(this.$store,this.$route,this.$router,'medicalInstitutionMessage');
          self.close();
          // this.Successdialog=false
        }
      },
    },
  };
</script>